package org.makcro.sms.services.chat.web.client.widgets.main;

import org.makcro.sms.services.chat.web.client.AppEvents;

import com.extjs.gxt.ui.client.event.MenuEvent;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.mvc.Dispatcher;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.extjs.gxt.ui.client.widget.menu.Menu;
import com.extjs.gxt.ui.client.widget.menu.MenuBar;
import com.extjs.gxt.ui.client.widget.menu.MenuBarItem;
import com.extjs.gxt.ui.client.widget.menu.MenuItem;

public class TopPanel extends ContentPanel {
	private MenuBar mbarMainMenu;
	private MenuBarItem menuBarItemApplication;
	private MenuItem menuItemLogout;
	public TopPanel() {
		setHeading("SMS Chat aplikacija");
		setLayout(new FitLayout());
		add(getMbarMainMenu());
		setBorders( false );
	}
	
	private MenuBar getMbarMainMenu() {
		if (mbarMainMenu == null) {
			mbarMainMenu = new MenuBar();
			mbarMainMenu.add(getMenuBarItemApplication());
		}
		return mbarMainMenu;
	}
	private MenuBarItem getMenuBarItemApplication() {
		if (menuBarItemApplication == null) {
			Menu menu = new Menu();
			menu.add(getMenuItemLogout());
			menuBarItemApplication = new MenuBarItem("Aplikacija", menu);
		}
		return menuBarItemApplication;
	}
	private MenuItem getMenuItemLogout() {
		if (menuItemLogout == null) {
			menuItemLogout = new MenuItem("Odjava");
			menuItemLogout.addSelectionListener(new SelectionListener<MenuEvent>() {
				public void componentSelected(MenuEvent ce) {
					Dispatcher.get().dispatch(AppEvents.LOGOUT_REQUESTED);
				}
			});
		}
		return menuItemLogout;
	}
}
